
package questionbook.standard;

import java.util.ArrayList;
import java.util.List;
import org.openrdf.model.URI;
import questionbook.Configuration.QuestionbookConfiguration;
import questionbook.manager.StoreManager;
import questionbook.model.AnswerClass;
import questionbook.model.AnswerType;
import questionbook.model.CommentType;
import questionbook.model.UserClass;

/**
 * This class provides all Identifiers for the QuestionBook Ontology
 *
 * @author stefanstift
 */
public class Qbook {

    private static Qbook instance;
    private StoreManager storeManager;

    private List<AnswerType> answerTypes = null;
    private List<CommentType> commentTypes = null;

    private String namespace = QuestionbookConfiguration.getInstance().getBaseURL();

    // GENERAL

    private String createdAt = namespace + "#createdAt";
    private String extStringId = namespace + "#extStringId";
    private String extLongId = namespace + "#extLongId";
    private String hasTitle = namespace + "#hasTitle";

    // FOAF EXTENSION
    private String md5Password = namespace + "#md5Password";

    // PREDICATES
    private String says = namespace + "#says";
    private String asks = namespace + "#asks";
    private String answers = namespace + "#answers";
    private String comments = namespace + "#comments";

    private String thinks = namespace + "#think";
    private String sure = namespace + "#sure";
    private String thinkWrong = namespace + "#thinkWrong";
    private String sureWrong = namespace + "#sureWrong";
    private String thinkRight = namespace + "#thinkRight";
    private String sureRight = namespace + "#sureRight";

    private String positive = namespace + "#positive";
    private String negative = namespace + "#negative";

    private String hasAnswer = namespace + "#hasAnswer";
    private String hasSuperAnswer = namespace + "#hasSuperAnswer";
    private String hasTrustAnswer = namespace + "#hasTrustAnswer";
    private String hasDoubtAnswer = namespace + "#hasDoubtAnswer";
    private String hasBadAnswer = namespace + "#hasBadAnswer";

    private String hasGoodCharma = namespace + "#hasGoodCharma";
    private String hasMediateCharma = namespace + "#hasMediateCharma";
    private String hasBadCharma = namespace + "#hasBadCharma";

    private String hasCategory = namespace + "#hasCategory";
    private String makes = namespace + "#makes";
    private String forQuestion = namespace + "#forQuestion";
    private String withPerson = namespace + "#withPerson";

    private String relatedQuestion = namespace + "#relatedQuestion";


     // FRIENDSHIP EXTENSTION
    private String asksFriendship = namespace + "#asksFriendship";

    // CLASSES

    private String suggest = namespace + "#Suggest";

    private String question = namespace + "#Question";
    private String answer = namespace + "#Answer";
    private String category = namespace + "#Category";
    private String comment = namespace + "#Comment";

    // ANSWER CLASSES
    private String expertAnswer = namespace + "#ExpertAnswer";
    private String superAnswer = namespace + "#SuperAnswer";
    private String trustAnswer = namespace + "#TrustAnswer";
    private String stdAnwser = namespace + "#StdAnswer";
    private String doubtAnwser = namespace + "#DoubtAnswer";
    private String badAnswer = namespace + "#BadAnswer";
    private String ignoreAnswer = namespace + "#IgnoreAnswer";

    // USER CLASSES
    private String expertUser = namespace + "#ExpertUser";
    private String trustUser = namespace + "#TrustUser";
    private String stdUser = namespace + "#StdUser";
    private String doubtUser = namespace + "#DoubtUser";
    private String beginnerUser = namespace + "#BeginnerUser";



    protected Qbook() {

        this.storeManager = StoreManager.getInstance();
    }

    public static Qbook getInstance()
    {
        if(instance == null)
            instance = new Qbook();

        return instance;
    }

    /**
     *
     * @return a List of the configured AnswerTypes
     */
    public List<AnswerType> getAnswerTypes()
    {
        if(this.answerTypes == null)
        {
            this.answerTypes = new ArrayList<AnswerType>();

            AnswerType a1 = new AnswerType(this.getThinksURI());
            a1.setLabel(QuestionbookConfiguration.getInstance().getThinkLabel());
            this.answerTypes.add(a1);

            AnswerType a2 = new AnswerType(this.getSureURI());
            a2.setLabel(QuestionbookConfiguration.getInstance().getSureLabel());
            this.answerTypes.add(a2);
        }
        return this.answerTypes;
    }

    /**
     *
     * @param type
     * @return the AnswerType Object for the specified String representation of the type
     */
    public AnswerType getAnswerType(String type)
    {
        if(type.equals(this.sure))
        {
            AnswerType a = new AnswerType(this.getSureURI());
            a.setLabel(QuestionbookConfiguration.getInstance().getSureLabel());
            return a;
        }
        else if(type.equals(this.thinks))
        {
            AnswerType a = new AnswerType(this.getThinksURI());
            a.setLabel(QuestionbookConfiguration.getInstance().getThinkLabel());
            return a;
        }

        return null;
    }

    /**
     *
     * @param answerClass
     * @return the URI for the specified AnswerClass
     */
    public URI getAnswerClassURI(AnswerClass answerClass)
    {
        if(answerClass == AnswerClass.ExpertAnswer)
            return this.getExpertAnserURI();
        else if(answerClass == AnswerClass.TrustAnswer)
            return this.getTrustAnswerURI();
        else if(answerClass == AnswerClass.StdAnswer)
            return this.getStdAnwserURI();
        else if(answerClass == AnswerClass.DoubtAnswer)
            return this.getDoubtAnwserURI();
        else if(answerClass == AnswerClass.BadAnswer)
            return this.getBadAnswerURI();
        else if(answerClass == AnswerClass.SuperAnswer)
            return this.getSuperAnwserURI();
        else if(answerClass == AnswerClass.IgnoreAnswer)
            return this.getIgnoreAnswerURI();

        return null;
    }

    /**
     *
     * @param answerClass
     * @return the right hasAnswer Property for the specified AnswerClass
     */
    public URI getHasAnswerPredicate (AnswerClass answerClass)
    {
        if(answerClass == AnswerClass.TrustAnswer)
            return this.getHasTrustAnswerURI();
        else if(answerClass == AnswerClass.DoubtAnswer)
            return this.getHasDoubtAnswerURI();
        else if(answerClass == AnswerClass.BadAnswer)
            return this.getHasBadAnswerURI();
        else if(answerClass == AnswerClass.SuperAnswer)
            return this.getHasSuperAnswerURI();
        else if(answerClass == AnswerClass.ExpertAnswer)
            return this.getHasSuperAnswerURI();
        else if(answerClass == AnswerClass.IgnoreAnswer)
            return this.getHasBadAnswerURI();

        return null;
    }

    /**
     *
     * @param userClass
     * @return the URI for the specified UserClass
     */
    public URI getUserClassURI(UserClass userClass)
    {
        if(userClass == UserClass.BeginnerUser)
            return this.getBeginnerUserURI();
        else if(userClass == UserClass.DoubtUser)
            return this.getDoubtUserURI();
        else if(userClass == UserClass.ExpertUser)
            return this.getExpertUserURI();
        else if(userClass == UserClass.StdUser)
            return this.getStdUserURI();
        else if(userClass == UserClass.TrustUser)
            return this.getTrustUserURI();

        return null;
    }

    /**
     *
     * @param answerClass
     * @return the AnswerClass for the specified String-Representation
     */
    public AnswerClass getAnswerClass(String answerClass)
    {
        if(answerClass.equals(this.expertAnswer))
            return AnswerClass.ExpertAnswer;
        else if(answerClass.equals(this.superAnswer))
            return AnswerClass.SuperAnswer;
        else if(answerClass.equals(this.trustAnswer))
            return AnswerClass.TrustAnswer;
        else if(answerClass.equals(this.stdAnwser))
            return AnswerClass.StdAnswer;
        else if(answerClass.equals(this.doubtAnwser))
            return AnswerClass.DoubtAnswer;
        else if(answerClass.equals(this.badAnswer))
            return AnswerClass.BadAnswer;
        else if(answerClass.equals(this.ignoreAnswer))
            return AnswerClass.IgnoreAnswer;

        return null;
    }

    /**
     *
     * @param userClass
     * @return the UserClass for the specified String-Representation
     */
    public UserClass getUserClass(String userClass)
    {
        if(userClass.equals(this.expertUser))
            return UserClass.ExpertUser;
        else if(userClass.equals(this.trustUser))
            return UserClass.TrustUser;
        else if(userClass.equals(this.stdUser))
            return UserClass.StdUser;
        else if(userClass.equals(this.doubtUser))
            return UserClass.DoubtUser;
        else if(userClass.equals(this.beginnerUser))
            return UserClass.BeginnerUser;
        
        return null;
    }

    /**
     *
     * @return a List of all configured CommentTypes
     */
    public List<CommentType> getCommentTypes()
    {
        if(this.commentTypes == null)
        {
            this.commentTypes =  new ArrayList<CommentType>();

            CommentType a1 = new CommentType(this.getThinkRightURI());
            a1.setLabel(QuestionbookConfiguration.getInstance().getThinkRightLabel());
            this.commentTypes.add(a1);

            CommentType a2 = new CommentType(this.getSureRightURI());
            a2.setLabel(QuestionbookConfiguration.getInstance().getSureRightLabel());
            this.commentTypes.add(a2);

            CommentType a3 = new CommentType(this.getThinkWrongURI());
            a3.setLabel(QuestionbookConfiguration.getInstance().getThinkWrongLabel());
            this.commentTypes.add(a3);

            CommentType a4 = new CommentType(this.getSureWrongURI());
            a4.setLabel(QuestionbookConfiguration.getInstance().getSureWrongLabel());
            this.commentTypes.add(a4);
        }

        return this.commentTypes;

    }

    /**
     *
     * @param type
     * @return the CommentType for the specified String-Representation
     */
    public CommentType getCommentType(String type)
    {
        if(type.equals(this.thinkRight))
        {
            CommentType c = new CommentType(this.getThinkRightURI());
            c.setLabel(QuestionbookConfiguration.getInstance().getThinkRightLabel());
            return c;
        }
        else if (type.equals(this.sureRight))
        {
            CommentType c = new CommentType(this.getSureRightURI());
            c.setLabel(QuestionbookConfiguration.getInstance().getSureRightLabel());
            return c;
        }
        else if (type.equals(this.thinkWrong))
        {
            CommentType c = new CommentType(this.getThinkWrongURI());
            c.setLabel(QuestionbookConfiguration.getInstance().getThinkWrongLabel());
            return c;
        }
        else if (type.equals(this.sureWrong))
        {
            CommentType c = new CommentType(this.getSureWrongURI());
            c.setLabel(QuestionbookConfiguration.getInstance().getSureWrongLabel());
            return c;
        }
        else if(type.equals(this.comments))
        {
            CommentType c = new CommentType(this.getCommentsURI());
            c.setLabel("neutral");
            return c;
        }

        return null;
    }


    public URI getAsksFriendshipURI()
    {
        return this.storeManager.getStore().getURIref(this.asksFriendship);
    }

    public URI getSaysURI()
    {
        return this.storeManager.getStore().getURIref(this.says);
    }

    public URI getCommentsURI()
    {
        return this.storeManager.getStore().getURIref(this.comments);
    }

    public URI getAsksURI()
    {
        return this.storeManager.getStore().getURIref(this.asks);
    }


    public URI getThinksURI()
    {
        return this.storeManager.getStore().getURIref(this.thinks);
    }

    public URI getSureURI()
    {
        return this.storeManager.getStore().getURIref(this.sure);
    }

    public URI getAnswersURI()
    {
        return this.storeManager.getStore().getURIref(this.answers);
    }

    public URI getThinkWrongURI()
    {
        return this.storeManager.getStore().getURIref(this.thinkWrong);
    }

    public URI getSureWrongURI()
    {
        return this.storeManager.getStore().getURIref(this.sureWrong);
    }

    public URI getThinkRightURI()
    {
        return this.storeManager.getStore().getURIref(this.thinkRight);
    }

    public URI getSureRightURI()
    {
        return this.storeManager.getStore().getURIref(this.sureRight);
    }

    public URI getQuestionURI()
    {
        return this.storeManager.getStore().getURIref(this.question);
    }

    public URI getCategoryURI()
    {
        return this.storeManager.getStore().getURIref(this.category);
    }

    public URI getMd5PasswordURI()
    {
         return this.storeManager.getStore().getURIref(this.md5Password);
    }


    public URI getHasCategoryURI()
    {
         return this.storeManager.getStore().getURIref(this.hasCategory);
    }

    public URI getCommentURI()
    {
         return this.storeManager.getStore().getURIref(this.comment);
    }

    public URI getAnswerURI()
    {
         return this.storeManager.getStore().getURIref(this.answer);
    }
    
    public URI getExpertAnserURI()
    {
         return this.storeManager.getStore().getURIref(this.expertAnswer);
    }

    public URI getBadAnswerURI() {
        return this.storeManager.getStore().getURIref(this.badAnswer);
    }

    public URI getDoubtAnwserURI() {
         return this.storeManager.getStore().getURIref(this.doubtAnwser);
    }

    public URI getStdAnwserURI() {
         return this.storeManager.getStore().getURIref(this.stdAnwser);
    }

    public URI getTrustAnswerURI() {
        return this.storeManager.getStore().getURIref(this.trustAnswer);
    }
    
    public URI getSuperAnwserURI() {
         return this.storeManager.getStore().getURIref(this.superAnswer);
    }

    public URI getIgnoreAnswerURI() {
        return this.storeManager.getStore().getURIref(this.ignoreAnswer);
    }

    public URI getNegativeURI() {
        return this.storeManager.getStore().getURIref(this.negative);
    }

    public URI getPositiveURI() {
        return this.storeManager.getStore().getURIref(this.positive);
    }

    public URI getBeginnerUserURI() {
       return this.storeManager.getStore().getURIref(this.beginnerUser);
    }

    public URI getDoubtUserURI() {
       return this.storeManager.getStore().getURIref(this.doubtUser);
    }

    public URI getExpertUserURI() {
        return this.storeManager.getStore().getURIref(this.expertUser);
    }

    public URI getStdUserURI() {
        return this.storeManager.getStore().getURIref(this.stdUser);
    }

    public URI getTrustUserURI() {
        return this.storeManager.getStore().getURIref(this.trustUser);
    }

    public URI getHasAnswerURI() {
        return this.storeManager.getStore().getURIref(this.hasAnswer);
    }

    public URI getHasBadAnswerURI() {
        return this.storeManager.getStore().getURIref(this.hasBadAnswer);
    }

    public URI getHasDoubtAnswerURI() {
        return this.storeManager.getStore().getURIref(this.hasDoubtAnswer);
    }

    public URI getHasSuperAnswerURI() {
        return this.storeManager.getStore().getURIref(this.hasSuperAnswer);
    }

    public URI getHasTrustAnswerURI() {
        return this.storeManager.getStore().getURIref(this.hasTrustAnswer);
    }

    public URI getHasBadCharmaURI() {
        return this.storeManager.getStore().getURIref(this.hasBadCharma);
    }

    public URI getHasGoodCharmaURI() {
        return this.storeManager.getStore().getURIref(this.hasGoodCharma);
    }

    public URI getHasMediateCharmaURI() {
        return this.storeManager.getStore().getURIref(this.hasMediateCharma);
    }

    public URI getForQuestionURI() {
         return this.storeManager.getStore().getURIref(this.forQuestion);
    }

    public URI getMakesURI() {
        return this.storeManager.getStore().getURIref(this.makes);
    }

    public URI getSuggestURI() {
         return this.storeManager.getStore().getURIref(this.suggest);
    }

    public URI getWithPersonURI() {
        return this.storeManager.getStore().getURIref(this.withPerson);
    }

    public URI getRelatedQuestionURI() {
         return this.storeManager.getStore().getURIref(this.relatedQuestion);
    }

    public URI getCreatedAtURI() {
        return this.storeManager.getStore().getURIref(this.createdAt);
    }

    public URI getExtLongIdURI() {
        return this.storeManager.getStore().getURIref(this.extLongId);
    }

    public URI getExtStringIdURI() {
        return this.storeManager.getStore().getURIref(this.extStringId);
    }

    public URI getHasTitleURI() {
        return this.storeManager.getStore().getURIref(this.hasTitle);
    }
}
